Ext.define('AmpleHarvest.objects.comments.view.Comments',
{
	extend :  'Ext.panel.Panel',
	alias  : 'widget.ampleharvest-objects-comments-view-comments',
	requires : [],
	border: false,
	postCommentButton: null,
	requestId: null,
 	width: 1220,
 	boxMinWidth: 1220,
	padding: '5,0,5,0',
     layout : 'fit',

	ajaxSuccessResponse: function(jsonResponse){
		var nameJsonArray = JSON.parse(jsonResponse.responseText);
		// Set Permisions
		this.bool_EditOwnS1 = nameJsonArray.data.HR_EDIT_OWN_STAGE1;
		this.bool_EditOwnS2 = nameJsonArray.data.HR_EDIT_OWN_STAGE2;
		this.bool_EditAllS1 = nameJsonArray.data.HR_EDIT_ALL_STAGE1;
		this.bool_EditAllS2 = nameJsonArray.data.HR_EDIT_ALL_STAGE2;
		this.bool_DeactivateAll = nameJsonArray.data.HR_REQUEST_DEACTIVATE_ALL;
		this.bool_DeactivateOwn = nameJsonArray.data.HR_REQUEST_DEACTIVATE_OWN;
		this.bool_ViewAll = nameJsonArray.data.HR_VIEW_ALL;
		
		this.commentGrid = 
			Ext.create('AmpleHarvest.objects.results.results', 
				{
					flex: 1,
					viewConfig: {
				        id: 'gv', // ID is reset to dynamic in initComponent
				        trackOver: false,
				        stripeRows: false,
				        plugins: [{
				            ptype: 'preview',
				            bodyField: 'comment',
				            expanded: true,
				            pluginId: 'preview'
				        }]
				    },
					store: Ext.create('AmpleHarvest.objects.comments.store.CommentsList',
						{
							AHcaller: this
						}
					),
					columns:
				      [
				            {
				               header      : "Commenter",
				               sortable : true,
				               dataIndex   	: 'commenter',
				               flex			: 1
				            },
				            {
				               header      : "Date",
				               sortable : true,
				               dataIndex   : 'comment_date',
				               flex			: 1
				            },
				            {
				                header      : "Comment",
				                sortable : true,
				                dataIndex   : '',
				                flex     : 5
				             }
				      ]
				}
				
			);
			
//			this.commentGrid.setConfigOptions('comment');
			
			this.commentGrid.getStore().proxy.setExtraParam('requestID', this.requestId);
		

//		this.commentGrid.add(this.commentsGridView = Ext.create("AmpleHarvest.objects.comments.view.CommentsGrid", nameJsonArray, this.requestId),
//			{
//				itemId: 'comment_grid',
//			} 
//		);
this.commentGrid.getStore().load();
		this.add(this.commentGrid);
	},

     initComponent : function()
     {
    	 
    	 Ext.QuickTips.init();
    	 
    	 this.callParent();
    	 
//    	 this.commentGrid = Ext.create("Ext.panel.Panel", 
//    		 {
//    		 	border: false
//    		 }
//    	 );
    	 
    	 Ext.Ajax.request(
    		 {
    			 url: obj_config.C_STR_EXTERNAL_PATH+'/rest/harvestrequest/GetHarvestPermissions.php',
    			 method  : "GET",
    			 scope: this,
    			 success: function(response, opts) {
    			 	this.ajaxSuccessResponse(response)
    			 },
    			 failure: function(response, opts) {
    			 }
    		 }
    	);
    	
    	
    	
     }
     
     
});